var querystring = require('querystring')
function main() {
    let long_url = args[0]
    let isRestful = payload.get().path == '/api/utils/sortUrl'
    if (isRestful) {
        long_url = payload.get().body?.toString()
        if (long_url == '') {
            long_url = payload.get().query.url[0]
        }
    }
    // console.log(long_url)
    let req = {
        url: 'https://sms.test.com/v2/short_url/shorten.json',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: querystring.stringify({
            apikey: 'xxx',
            long_url: long_url,
        }),
    }

    let res = request.parse(req).body.toObject()

    if (isRestful) {
        return okMsg(res.short_url)
    }

    // console.log(JSON.stringify(res))

    return res
}